package com.activiti.tool;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.Deployment;

import java.io.InputStream;
import java.util.zip.ZipInputStream;

/**
 * 将流程模板打包上传
 *
 * @author ldanniel
 */
public class PackageBPMNResourceUpLoad {
    public static void main(String[] args) {
        PackageBPMNResourceUpLoad resourceUpLoad = new PackageBPMNResourceUpLoad();
        resourceUpLoad.resourceUpload();
    }

    /**
     * 将流程模板打包上传
     */
    public void resourceUpload() {
        //创建
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        //repositoryService
        RepositoryService repositoryService = processEngine.getRepositoryService();
        //流程部署
        InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("bpmn/evection.zip");
        assert inputStream != null;
        ZipInputStream zipInputStream = new ZipInputStream(inputStream);
        Deployment deploy = repositoryService.createDeployment()
                .disableSchemaValidation() //禁用架构验证
                .addZipInputStream(zipInputStream).deploy();
        System.out.println("部署流程的id" + deploy.getId());
        //部署流程的名称为空，是因为压缩包中可能有多个流程图，所以不能统一命名
        System.out.println("部署流程的名称" + deploy.getName());
    }
}
